import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';

import { ErrorMessageMode } from '/#/axios';
import {ContentTypeEnum} from "/@/enums/httpEnum";
enum Api {
  Login = '/login',
  LoginDms = '/gensoft/Login.html',
  Logout = '/logout',
  LogoutDms = '/gensoft/logout.html',
  GetUserInfo = '/getUserInfo',
  GetPermCode = '/getPermCode',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  //登录后端，获取session
  //欧马可   wanglong5@foton.com.cn
  //奥铃     yangli
  //图雅诺   SC000087337
  defHttp.post({ url: Api.LoginDms, params: {'tmUser.username':'yangli','tmUser.password':'Jhkj@Foton.2024.APP*','tmUser.key':5289} });
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
      headers: { 'Content-Type': ContentTypeEnum.JSON },
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  //退出DMS
  defHttp.post({ url: Api.LogoutDms });
  return defHttp.get({ url: Api.Logout });
}
